package cn.hanyx.coder.design.pattern.creational.singleton;

import java.util.concurrent.atomic.AtomicLong;

/**
 * IdDemo02
 *
 * @author hanyx
 * @date 2020/07/14
 */
public class IdDemo02 {
    private IdDemo02() {
    }

    private AtomicLong id = new AtomicLong(0);

    private static class Singleton02 {
        private static final IdDemo02 instance = new IdDemo02();

    }

    public long getId() {
        return id.incrementAndGet();
    }

    public static IdDemo02 getInstance() {
        return Singleton02.instance;
    }

    public static void main(String[] args) {
        System.out.println(IdDemo02.getInstance().getId());
    }
}
